@extends('admin.layout')

@section('content')
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding-top: 30px; text-align: center;">
        <form class="layui-form" action="{{route('admin.block.update',$block)}}" method="post">
            @include('site.block._form')
        </form>
    </div>
@endsection

@section('js')
    <script>
        layui.config({
            base: '/static/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function(){
            var $ = layui.$
                ,form = layui.form
                ,admin = layui.admin;
            //监听提交
            form.on('submit(layuiadmin-app-form-submit)', function(data){
                var field = data.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

                //提交 Ajax 成功后，关闭当前弹层并重载表格
                admin.req({
                    url: data.form.action
                    ,method: 'put'
                    ,datatype:'json'
                    ,data: field
                    ,done: function(res){
                        if(res.code===0){
                            layer.msg(data.msg, {icon: 6});
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    }
                });

                parent.layui.table.reload('LAY-app-content-block'); //重载表格
                parent.layer.close(index); //再执行关闭
            });
        })
    </script>
    @include('site.block._js')
@endsection
